part of 'page.dart';

class _SettingsPageWloc extends StatefulWloc<_SettingsPageWlocState, SettingsPage> {
  late final bloc.SettingsPageBloc _bloc;

  @override
  _SettingsPageWlocState get initialState {
    return _SettingsPageWlocStateFactory().create(
      blocState: _bloc.state,
    );
  }

  void onAppearanceSettingsTilePressed() {
    _bloc.requestAppearanceSettingsPageOpening();
  }

  void onImageSettingsTilePressed() {
    _bloc.requestImageSettingsPageOpening();
  }

  void onPronunciationSettingsTilePressed() {
    _bloc.requestPronunciationSettingsPageOpening();
  }

  void onLanguageSettingsTilePressed() {
    _bloc.requestLanguageSettingsPageOpening();
  }

  void _onBlocStateChanged(bloc.SettingsPageBlocState blocState) {
    final updatedState = _SettingsPageWlocStateFactory().create(
      blocState: blocState,
    );

    emit(updatedState);
  }

  @override
  void initState() {
    super.initState();

    _bloc = bloc.SettingsPageBloc(
      settingsBloc: core_di.sl(),
      menuNavigatorBloc: core_di.sl(),
    );

    _bloc.stream.listen(_onBlocStateChanged);
  }

  @override
  void dispose() {
    _bloc.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _SettingsPageView(
      wloc: this,
    );
  }
}
